/*    */ package com.zimbra.cs.service.account;
/*    */ 
/*    */ import com.zimbra.common.account.Key.SignatureBy;
/*    */ import com.zimbra.common.account.SignatureUtil;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AccountConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.Signature;
/*    */ import com.zimbra.soap.DocumentHandler;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.HashMap;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class ModifySignature
/*    */   extends DocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 39 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 40 */     Account account = getRequestedAccount(zsc);
/*    */     
/* 42 */     if (!canModifyOptions(zsc, account)) {
/* 43 */       throw ServiceException.PERM_DENIED("can not modify options");
/*    */     }
/* 45 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 47 */     Element eSignature = request.getElement("signature");
/*    */     
/* 49 */     Signature signature = null;
/* 50 */     String id = eSignature.getAttribute("id");
/* 51 */     signature = prov.get(account, Key.SignatureBy.id, id);
/* 52 */     if (signature == null) {
/* 53 */       throw AccountServiceException.NO_SUCH_SIGNATURE(id);
/*    */     }
/* 55 */     List<Element> contents = eSignature.listElements("content");
/* 56 */     Map<String, Object> attrs = new HashMap();
/* 57 */     for (Element eContent : contents) {
/* 58 */       String type = eContent.getAttribute("type");
/* 59 */       String attr = SignatureUtil.mimeTypeToAttrName(type);
/* 60 */       if (attr == null)
/* 61 */         throw ServiceException.INVALID_REQUEST("invalid type " + type, null);
/* 62 */       if (attrs.get(attr) != null) {
/* 63 */         throw ServiceException.INVALID_REQUEST("only one " + type + " content is allowed", null);
/*    */       }
/* 65 */       String content = eContent.getText();
/* 66 */       if (content != null) {
/* 67 */         attrs.put(attr, content);
/*    */       }
/*    */     }
/* 70 */     String name = eSignature.getAttribute("name", null);
/* 71 */     if (name != null) {
/* 72 */       attrs.put("zimbraSignatureName", name);
/*    */     }
/* 74 */     Element eContactId = eSignature.getOptionalElement("cid");
/* 75 */     if (eContactId != null) {
/* 76 */       attrs.put("zimbraPrefMailSignatureContactId", eContactId.getText());
/*    */     }
/* 78 */     prov.modifySignature(account, signature.getId(), attrs);
/*    */     
/* 80 */     Element response = zsc.createElement(AccountConstants.MODIFY_SIGNATURE_RESPONSE);
/* 81 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/account/ModifySignature.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */